package com.example.jdk8.threads;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class ThreadScheduledExecutorByPeriod {
    public static void main(String[] args) throws InterruptedException {
        // 初始化线程池
        ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
        // 创建线程实例
        Runnable task = () -> {
            System.out.println();
            System.out.println("Scheduling: "+ System.nanoTime());
        };
        int initialDelay = 0;
        int period = 1;
        // 按照指定频率创建线程任务
        executorService.scheduleAtFixedRate(task, initialDelay, period, TimeUnit.SECONDS);
    }
}
